package day4;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class CalendarTest6 {
    //1,234元
    public static void main(String[] args) {
        Date d=new Date();
        System.out.println(d);
        //Date =>String
        //String=>Date
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm");
        //Date->String
        String str = df.format(d);
        System.out.println(str);
        Scanner in=new Scanner(System.in);
        System.out.println("字符串转换成日期：");
        SimpleDateFormat df2=new SimpleDateFormat();
        df2.applyPattern("yyyy.MM.dd");//修改格式
        df2.setLenient(false);//不启用宽松格式
        System.out.println("输入日期：");
        String ds=in.next();
        //String=>Date
        try {
            Date date = df2.parse(ds);
            System.out.println(date);
            Calendar cc=Calendar.getInstance();
            cc.setTime(date);//Date ->Calendar

        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
